module.exports = function ($scope, $resource, $modalInstance, bean, toaster, FileUploader) {
    $scope.bean = bean;
    console.log(bean);
    $resource('/api/as/mc/shoporder/findOrderProfitList', {}, {}).save({ order_code: $scope.bean.order_code }, function (res) {
        if (res.errcode === 0) {
            $scope.beanList = res.data;
            angular.forEach(res.data, function(item){
                item.price_typeshow = true;
                item.track_typeshow = true;
                item.show = true;
            });
        } else {
            toaster.error({ title: '', body: res.errmsg });
        }
    });

    //保存
    $scope.ok = function () {
        $modalInstance.close();
    }

    //取消
    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }
    //筛选
    $scope.cheak = function () {
        $scope.beanList = [];
        for(var i in $scope.baseList){
            if($scope.price_type != 'all'){
                if($scope.baseList[i].price_type == $scope.price_type){
                    if($scope.track_type != 'all'){
                        if($scope.baseList[i].track_type == $scope.track_type){
                            $scope.beanList.push($scope.baseList[i]);
                        }
                    }else{
                        $scope.beanList.push($scope.baseList[i]);
                    }
                }
               
            }else{
                if($scope.track_type != 'all'){
                    if($scope.baseList[i].track_type == $scope.track_type){
                        $scope.beanList.push($scope.baseList[i]);
                    }
                }else{
                    $scope.beanList.push($scope.baseList[i]);
                }
            }
        }
        
    }
    $scope.filters = {
        'list1': [
            {'label': '预计收益', 'show': true, 'value': 'estimate'},
            {'label': '实际收益', 'show': true, 'value': 'actual'},
        ],
        'list2': [
            {'label': '分销利润', 'show': true, 'value': 'sale_profit'},
            {'label': '店铺利润', 'show': true, 'value': 'shop_profit'},
            {'label': '店铺成本', 'show': true, 'value': 'shop_cost'},
            {'label': '店铺手续费', 'show': true, 'value': 'shop_charge'},
        ],
        'open1': false,
        'open2': false,
    };
    

    $scope.filterType = function(obj){
        obj.show = !obj.show;
        angular.forEach($scope.beanList, function(item){
            if(item.price_type == obj.value){
                item.price_typeshow = obj.show;
                if(item.price_typeshow == true && item.track_typeshow == true){
                    item.show = true;
                }else{
                    item.show = false;
                }
            }
        });
    }

    $scope.selectFlag = function(list, flag){
        angular.forEach(list, function(obj){
            obj.show = flag;
            angular.forEach($scope.beanList, function(item){
                if(item.price_type == obj.value){
                    item.price_typeshow = obj.show;
                    if(item.price_typeshow == true && item.track_typeshow == true){
                        item.show = true;
                    }else{
                        item.show = false;
                    }
                }
            });
        });
    }

    $scope.filterType1 = function(obj){
        obj.show = !obj.show;
        angular.forEach($scope.beanList, function(item){
            if(item.track_type == obj.value){
                item.track_typeshow = obj.show;
                if(item.price_typeshow == true && item.track_typeshow == true){
                    item.show = true;
                }else{
                    item.show = false;
                }
            }
        });
    }

    $scope.selectFlag1 = function(list, flag){
        angular.forEach(list, function(obj){
            obj.show = flag;
            angular.forEach($scope.beanList, function(item){
                if(item.track_type == obj.value){
                    item.track_typeshow = obj.show;
                    if(item.price_typeshow == true && item.track_typeshow == true){
                        item.show = true;
                    }else{
                        item.show = false;
                    }
                }
            });
        });
        
    }
};